<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no" />
    <title>注册页面</title>
    <link rel="stylesheet" type="text/css" href="css/regedit.css"/>
    <script>
        function regeditCheck(){
            var username=document.getElementById("_username").value;
            var password=document.getElementById("_password").value;
            var password1=document.getElementById("_password1").value;
            if(!username){
                alert("请输入用户名！");
                return false;
            }
            if(!password){
                alert("请输入密码!");
                return false;
            }
            if(!password1){
                alert("请再次输入密码!");
                return false;
            }
            if(!(password1==password)){
                alert("两次密码输入不同！");
                return false;
            }
        }
    </script>
</head>
<body>
<?php
header("content-type:text/html;charset=utf-8");
include('config.php');
$regeditErr="";
if (!$link) {
    die("连接失败: " . mysqli_connect_error());
}
if($_SERVER["REQUEST_METHOD"]=="POST") {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $pwd_again = $_POST['pwd_again'];
    $sqlIsset="select username from user where username={$username}";
    $rs=mysqli_query($link,$sqlIsset);
    $row = mysqli_fetch_assoc($rs);
    if($row){
        $regeditErr="此用户名已存在!";
    }else{
        $sql = "insert into user(username,password) values('$username','$password')";
        $result = mysqli_query($link, $sql);
        if (!$result) {
            echo "注册不成功！" . "<br/><br/>";
        } else {
            echo "注册成功!正在跳转至登录界面...";
            header("refresh:2;url=login.php");//一秒后登录到主页,url可以是本地相对路径,也可以是http://链接
        }
    }

}
?>

        <h1>请牢记你的注册信息</h1>
    <form name="form1" id="form1" method="post" action="">
        <p><input type="text" class="pf_ipt_user" placeholder="请输入账号" autocomplete="off" name="username" id="_username" tabindex="1"/></p>
        <p><input type="password" class="pf_ipt_pass pass_bg_1" placeholder="请输入密码" autocomplete="off" name="password" id="_password" tabindex="2"/></p>
        <p><input type="password" class="pf_ipt_pass pass_bg_1" placeholder="请再输入一次密码" autocomplete="off" name="pwd_again" id="_password1" tabindex="3"/></p>

        <?php echo $regeditErr; ?>
        <p><button  class="btn_1 w430" onclick="return regeditCheck()">确认注册</button></p>
    </form>

</body>
</html>
